package cn.fws.meap.user.service.impl;

import java.util.List;

import cn.fws.meap.user.mapper.UserMapper;
import cn.fws.meap.user.vo.UserDetailsVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import cn.fws.framework.utils.ConvertUtils;
import cn.fws.framework.utils.UUIDUtils;
import cn.fws.meap.user.mapper.ConcernMapper;
import cn.fws.meap.user.entity.Concern;
import cn.fws.meap.user.service.IConcernService;
import org.springframework.transaction.annotation.Transactional;

/**
 * 关注用户 服务层实现
 * 
 * @author chenkh
 * @date 2019-03-07
 */
@Service
@Transactional
public class ConcernServiceImpl implements IConcernService {

	@Autowired
	private ConcernMapper concernMapper;
	@Autowired
	private UserMapper userMapper;

	/**
     * 查询关注用户信息
     * 
     * @param id 关注用户ID
     * @return 关注用户信息
     */
    @Override
	public Concern selectById(String id) {
	    return concernMapper.selectById(id);
	}
	
	/**
     * 查询关注用户列表
     * 
     * @param concern 关注用户信息
     * @return 关注用户集合
     */
	@Override
	public List<Concern> selectList(Concern concern)	{
	    return concernMapper.selectList(concern);
	}
	
    /**
     * 新增关注用户
     * 
     * @param
     * @return 结果
     */
	@Override
	public int insert(String selfOpenid,String itOpenid) {
		//暂时先不加 is_atten 是否关注的状态


		Concern concern = new Concern();
		// 设置主键
		concern.setId(UUIDUtils.getUUID());
		// 设置创建时间
		concern.setAttenTime(new java.util.Date());
		//被关注【粉丝】
		concern.setOpenid(selfOpenid);
		//关注
		concern.setAttenOpenid(itOpenid);

	    return concernMapper.insert(concern);
	}
	
	/**
     * 修改关注用户
     * 
     * @param concern 关注用户信息
     * @return 结果
     */
	@Override
	public int update(Concern concern) {
		// 设置修改时间
		concern.setUpdateTime(new java.util.Date());
	    return concernMapper.update(concern);
	}

	/**
     * 删除关注用户对象
     * 
     * @param ids 需要删除的数据ID
     * @return 结果
     */
	@Override
	public int deleteByIds(String ids) {
		return concernMapper.deleteByIds(ConvertUtils.toStrArray(ids));
	}

	/**
	 * 关注的状态
	 * @param selfOpenId
	 * @param itOpenId
	 * @return
	 */
	@Override
	public Concern selectConcernStatus(String selfOpenId, String itOpenId) {
		Concern concernStatus=concernMapper.selectConcernStatus(selfOpenId,itOpenId);
		return concernStatus;
	}

	/**
	 * 删除关注状态
	 * @param selfOpenid
	 * @param itOpenid
	 * @return
	 */
	@Override
	public int deleteByOpenId(String selfOpenid, String itOpenid) {

		int delete=concernMapper.deleteByOpenId(selfOpenid,itOpenid);

		return delete;
	}


	/**
	 * 获取所用粉丝的用户
	 * @param clickOpenid 点击用户详情的id
	 * @param selfOpenid 当前用户id
	 * @return
	 */
	@Override
	public List<UserDetailsVo> getFansList(String clickOpenid,String selfOpenid) {
		List<UserDetailsVo> selectUserFansList=userMapper.selectUserFansList(clickOpenid,selfOpenid);

		return selectUserFansList;
	}

	/**
	 * 获取关注的用户
	 * @param clickOpenid 点击用户详情的id
	 * @param selfOpenid 当前用户id
	 * @return
	 */
	@Override
	public List<UserDetailsVo> getConcernList(String clickOpenid,String selfOpenid) {
		List<UserDetailsVo> selectUserConernList = userMapper.selectUserConernList(clickOpenid,selfOpenid);
		return selectUserConernList;
	}

}
